<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <p>
    当前的ip是
    <span id="ip"></span>
  </p>

  <script>
    window.onload = function () {
      var xhr = new XMLHttpRequest();
      xhr.open('GET', 'https://api.ipify.org', true);
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            var ip = xhr.responseText;
            console.log(ip);
            document.getElementById('ip').innerHTML = ip;
            // 将ip地址写入数据库
          } else {
            console.error(xhr.statusText);
          }
        }
      }
      xhr.send('nulL');
    }

  </script>
</body>
</html>